<?php
class SmsApiModel{
    public function sendSMS($mobile,$message){
        Zend_Loader::loadClass("SmsSendModel");
        $smsSendModel=new SmsSendModel();
        $date=new Zend_Date();
        $sms_id=$smsSendModel->insert(array(
            "mobile"=>$mobile,
            "message"=>$message,
            "time"=>$date->toString("yyyy-MM-dd HH:mm:ss")
        ));
        $client=new Zend_Http_Client(LINK_FIBO_API."/SendSMS");
        //Test gửi SMS serverType=3;
        $client->setParameterPost(array(
            "clientNo"=>FIBO_CLIENT_NO,
            "clientPass"=>FIBO_CLIENT_PASS,
            "phoneNumber"=>$mobile,
            "smsMessage"=>$message,
            "smsGUID"=>$sms_id,
            "serviceType"=>3
        ));
        $response=$client->request("POST");
        $response=$response->getBody();
        preg_match('/&lt;Code&gt;(.*?)&lt;\/Code&gt;/',$response, $code);
        preg_match('/&lt;Message&gt;(.*?)&lt;\/Message&gt;/',$response, $message);
        $smsSendModel->update(array("code"=>@$code[1],"message"=>$message[1]), "id='".$sms_id."'");
        $code=@$code[1];
        return $code;
       /*  $data="clientNo=".FIBO_CLIENT_NO."&".
        "clientPass=".FIBO_CLIENT_PASS."&".
        "phoneNumber=".$mobile."&".
        "smsMessage=".$message."&".
        "smsGUID=&".
        "serviceType=3";
        $xml_response=simplexml_load_file(LINK_FIBO_API."/SendSMS?".$data); */
    }
    public function sendSMSToList($message,$list_phone){
        Zend_Loader::loadClass("SmsSendModel");
        $smsSendMode=new SmsSendModel();
        $client=new Zend_Http_Client(LINK_FIBO_API."/SendSMSToListMobilePhone");
        /* <Document>
        <ListMobilePhone>
        <PhoneNumber>0903636635</PhoneNumber>
        <SMSGUID>acce8d19-2106-46f9-a2d1-8b7991f30232</SMSGUID>
        </ListMobilePhone>
        <ListMobilePhone>
        <PhoneNumber>8122</PhoneNumber>
        <SMSGUID>62c55648-29fb-4765-9ec4-a591f0a2b29f</SMSGUID>
        </ListMobilePhone>
        </Document> */
        $client->setParameterPost(array(
        		"clientNo"=>FIBO_CLIENT_NO,
        		"clientPass"=>FIBO_CLIENT_PASS,
        		"listPhoneNumber"=>$list_phone,
        		"smsMessage"=>$message,
        		"smsGUID"=>"",
        		"serviceType"=>3,
                "senderName"=>"n/a"
        ));
        $response=$client->request("POST");
        $response=$response->getBody();
        preg_match('/&lt;Code&gt;(.*?)&lt;\/Code&gt;/',$response, $code);
        $code=@$code[1];
        return $code;
    }
}